# 组合指的是某一个对象拥有一个属性,该属性的值是另外一个类的对象
"""
class Foo:
    xxx = 100
class Bar:
    yyy = 200
    def zzz(self):
        print("我是bar方法")
obj = Foo()
obj1 = Bar()
# print(obj1.yyy)
obj.guanbowen = obj1 # 将obj1对象赋值给obj对象的attr实例属性
print(obj.guanbowen) # <__main__.Bar object at 0x021E4550>
print(obj1) # <__main__.Bar object at 0x01854550>

# 因为obj1和obj.guanbowen的地址值一样，所以调用的yyy类属性也都是一个
print(obj1.yyy) # 200
print(obj.guanbowen.yyy) # 200
"""

# 为什么要用组合
"""
class People:
    school = '不造啊'
    def __init__(self,name,age,sex):
        self.name = name
        self.age = age
        self.sex = sex
class Student(People):
    def __init__(self, name, age, sex,score=0):
        super().__init__(name, age, sex)
        self.score = score
class Teacher(People):
    def __init__(self,name,age,sex,course=[]):
        super().__init__(name, age, sex)
        self.course=course
    def tell_info1(self):
        for i in self.course: # [python,math,English,music]
            i.tell_info() # python.tell_info()

class Course:
    def __init__(self,c_name,c_price):
        self.c_name = c_name
        self.c_price = c_price
    def tell_info(self):
        print('<课程名:%s,价格%s>'%(self.c_name,self.c_price))

python = Course('python开发',10000)
math = Course('高等数学',3000)
English = Course('英语',4000)
music = Course('音乐',5000)
drawing = Course('绘画',6000)

dahai = Teacher('龙仔',24,'man')

# 把music课程对象添加到老师对象tea的属性里面
dahai.course.append(music)
dahai.course.append(English)
dahai.course.append(drawing)
dahai.course.append(python)
dahai.course.append(math)

# [music,English,drawing,python,math]
# for i in [music,English,drawing,python,math]:
#      i.tell_info()
# music.tell_info()
# <音乐,5000>
dahai.tell_info1()
"""






